/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.dao;

import java.util.Date;

import net.iwsh.core.db.DBExecutor;

import com.us.usws.model.domain.system.UserLoginLog;
import com.us.usws.model.flat.system.DOUserLoginLog;

/**
 * DAO class
 * @author robot
 */
public class UserLoginLogDAO {

	/**
	 * Query SQLs
	 */

	private static final String SQL_GET_LAST_USER_LOGIN_LOG = "select * from sys_user_login_log where user_uid = ? order by login_date desc limit 0,1";
	private static final String SQL_GET_LAST_USER_LOGIN_DATE = "select login_date from sys_user_login_log where user_uid = ? order by login_date desc limit 0,1";

	/**
	 * CUR SQLs
	 */
	private static final String SQL_INSERT_USERLOGINLOG = "insert into sys_user_login_log(user_uid,login_date,ip_addr,is_success) values (?,?,?,?)";

	/**
	 * DBExeutor
	 */
	private DBExecutor dbe = new DBExecutor();

	/**
	 * Get UserLoginLog by primary key.
	 */
	public UserLoginLog getUserLastLoginLog(String userUid) {
		UserLoginLog u = dbe.load(SQL_GET_LAST_USER_LOGIN_LOG, UserLoginLog.class, userUid);
		return u;
	}

	/**
	 * Get UserLoginLog by primary key.
	 */
	public Date getUserLastLoginDate(String userUid) {
		Date u = dbe.load(SQL_GET_LAST_USER_LOGIN_DATE, Date.class, userUid);
		return u;
	}

	/**
	 * Insert one row.
	 */
	public String insertUserLoginLog(DOUserLoginLog userLoginLog) {
		dbe.execute(SQL_INSERT_USERLOGINLOG, userLoginLog.getUserUid(), userLoginLog.getLoginDate(), userLoginLog.getIpAddr(),
				userLoginLog.getIsSuccess());
		return userLoginLog.getUserUid();
	}

}